<?php

namespace Console\Logic;

use \Common\Logic\BaseLogic;

class LoginLogic extends BaseLogic
{
    private $adminModel;
    static $field = "id,cover,url";

    public function __construct()
    {
        parent::__construct();
        $this->adminModel = D('Admin');
    }

    /**
     * 获取用户信息
     * @param string $id
     * @param string $phone
     * @return mixed
     */
    public function getUserInfo($id = '', $phone = '')
    {
        if (empty($id) && empty($phone)) {
            return static::$res->err("userId和手机号不能同时为空");
        }

        $where = array();
        if (!empty($id)) {
            $where['id'] = $id;
        }
        if (!empty($phone)) {
            $where['phone'] = $phone;
        }

        $info = $this->adminModel->where($where)->find();
        if (empty($info)) {
            return static::$res->err("未找到用户");
        }

        return static::$res->suc("成功", $info);

    }

    public function addUser($phone, $password, $role = 3, $userId = '')
    {
        if (empty($phone)) {
            return static::$res->err("手机号不能为空");
        }

        if (!validate($phone, 'mobile')) {
            return static::$res->err("手机号格式错误");
        }

        if (empty($password)) {
            return static::$res->err("密码不能为空");
        } else {
            $password = md5($password);
        }


    }

}
